package com.gimi.cloud.jimi.dao.dao.homePage;


import com.gimi.cloud.jimi.dao.dao.sys.BaseDao;
import com.gimi.cloud.jimi.dao.myMapper.MyMapper;
import com.gimi.cloud.jimi.dao.myMapper.core.query.QueryParam;
import com.gimi.cloud.jimi.dao.myMapper.core.query.QueryParamProvider;
import com.gimi.cloud.jimi.dto.app.AdDTO;
import com.gimi.cloud.jimi.dto.app.ColumnDTO;
import com.gimi.cloud.jimi.dto.app.ColumnProdDTO;
import com.gimi.cloud.jimi.dto.product.ProductDto;
import com.gimi.cloud.jimi.entity.app.ColumnProdEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 栏位商品dao
 *
 * @author chendi
 * @date 2018年1月16日
 */
@Mapper
public interface ColumnProdDao extends MyMapper<ColumnProdEntity>, BaseDao {

    @Select("SELECT p.prod_id,p.prod_name,p.ad_img,p.prod_adword,p.prod_rent_price FROM jimi_column_prod c LEFT JOIN ec_product p ON c.prod_id = p.prod_id WHERE c.column_id = #{columnId} ORDER BY c.sort DESC")
    List<ProductDto> selectByColumuId(@Param(value = "columnId") Integer columnId);

    /**
     * 获得栏目下管理商品列表（分页），支持条件查询
     *
     * @param columnProdDTO
     * @return
     */
    List<ColumnProdDTO> queryPageList(ColumnProdDTO columnProdDTO);

    @Select("SELECT jcp.*,ep.prod_name FROM  jimi_column_prod jcp LEFT JOIN ec_product ep ON jcp.prod_id=ep.prod_id where column_id = #{columnId} ORDER BY jcp.sort DESC")
    List<ColumnProdDTO> adRelyColumnProd(AdDTO adDTO);

    /**
     * 广告对应的商品分页查询
     *
     * @param queryParam
     * @return
     */
    @SelectProvider(type = QueryParamProvider.class, method = "selectListBySql")
    List<ColumnProdDTO> adRelyColumnProdPage(QueryParam queryParam);

    /**
     * 通过columnId查询出对应的栏目下商品
     * @param columnDTO
     * @return
     */
    @Select("select * from jimi_column_prod where column_id = #{columnId}")
    List<ColumnProdEntity> selectColumnProdByColumnId(ColumnDTO columnDTO);

    /**
     * 通过栏目ID和商品ID确定唯一的ColumnProdEntity
     * @param columnProdDTO
     * @return
     */
    @Select("select * from jimi_column_prod where column_id = #{columnId} and prod_id=#{prodId} LIMIT 1")
    ColumnProdEntity selectColumnProdByColumnIdAndProdId(ColumnProdDTO columnProdDTO);

    @Delete("DELETE FROM jimi_column_prod WHERE column_id = #{columnId};")
    Integer deleteByColumnId(@Param(value = "columnId") Integer columnId);

    @Select("SELECT p.prod_id as prodId,p.prod_name as prodName,cp.sort FROM jimi_column_prod cp LEFT JOIN ec_product p ON cp.prod_id = p.prod_id WHERE cp.column_id = #{columnId} ORDER BY cp.sort DESC")
    List<Map> getCheckedProdByColumnId(@Param(value = "columnId") Integer columnId);
}
